package mx.com.mindbits.bandpay.utils;


import mx.com.mindbits.bandpay.R;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

public class cardDialog extends Dialog{
	
	private Context context = null;
	private EditText cvv;
	private TextView tvTitle;
	private TextView tvMessage;
	private ImageView ivImage;
	private String title;
	private String mesage;
	private Button button;
	
	
	
	public cardDialog(Context context, String title,String message){
		super(context);
		this.context =context;
		this.title = title;
		this.mesage = message;
	}
	
		//creacion de la interfaz
	public interface DialogListener{
		void finish(String CVV);
		
	}

	//libera acciones
	DialogListener dialogListener;
	
	//para instamviar al listener
	@Override
	public void onCreate(Bundle savedInstanceBundle){
		super.onCreate(savedInstanceBundle);
		setContentView(R.layout.custom_alert_dialog_cvv2);
		
		tvTitle = (TextView) findViewById(R.id.titleAlertText);
		tvMessage = (TextView) findViewById(R.id.messageText);
		ivImage = (ImageView) findViewById(R.id.imageDialog1);
		button = (Button) findViewById(R.id.bt_delete);
		button.setBackgroundResource(R.drawable.button_disable_shape);
		button.setEnabled(false);
		tvTitle.setText(title);
		tvMessage.setText(mesage);
		ivImage.setImageResource(R.drawable.cvv2_tiny);
		
		cvv = (EditText)  findViewById(R.id.cvv2Capture);
		cvv.addTextChangedListener(new TextWatcher(){

			@Override
			public void afterTextChanged(Editable arg0) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void beforeTextChanged(CharSequence arg0, int arg1,
					int arg2, int arg3) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void onTextChanged(CharSequence arg0, int arg1, int arg2,
					int arg3) {
				// TODO Auto-generated method stub
				if( arg0.length() == 3){
					button.setEnabled(true);
					cvv.setTextColor(Color.BLACK);
					button.setBackgroundResource(R.drawable.blue_button_shape);
				}else if(arg0.length() != 3){
					cvv.setTextColor(Color.RED);
					button.setEnabled(false);
					button.setBackgroundResource(R.drawable.button_disable_shape);
				}
			}
			
		});
		
		
		button.setOnClickListener(new positiveClick());
		
	}
	
	
	private class positiveClick implements android.view.View.OnClickListener{

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			dialogListener.finish(cvv.getText().toString());
			
			cardDialog.this.dismiss();
		}
		
	}
	
	
	
	
	//metodo
	public void setDialogResult(DialogListener listener){
		dialogListener =  listener;
	}
}
